//进行API统一管理
import requests from "./request";
import requestCenter from "../requests";
// 人员进出
export function getCombined() {
  const now = new Date();
  const oneWeekAgo = new Date(now);
  oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
  oneWeekAgo.setHours(0, 0, 0, 0);

  const oneWeekAgoStr = formatDate(oneWeekAgo);
  const nowStr = formatDate(now);

  return requestCenter({
    url: "/equipmentManagement/combined",
    method: "post",
    data: { pageNum: 1, pageSize: 100, startSwingTime: oneWeekAgoStr, endSwingTime: nowStr },
    headers: {
      "Content-Type": "application/json",
    },
  });
}

function formatDate(date) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');
  const minutes = String(date.getMinutes()).padStart(2, '0');
  const seconds = String(date.getSeconds()).padStart(2, '0');

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

//前端设备告警数据
export function getAlarmNotice() {
  return requests({
    url: "/ioc/jtwl/getAlarmNoticeListforSH",
    method: "get",
    // params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

//工业生产总值
export function getEnergy() {
  return requests({
    url: "/ioc/eco/getEnergyTotal",
    method: "get",
    // params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

//能耗分析
export function getConsumption(params) {
  return requests({
    url: "/ioc/eco/energy/consumption",
    method: "get",
    params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}


//能耗分析
export function getLand() {
  return requests({
    url: "/ioc/eco/park/land",
    method: "get",
    // params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

//安防监控列表
export function getListMonitor() {
  return requestCenter({
    url: "/equipmentManagement/securityEquipment",
    method: "get",
    // params: params,
  });
}

// 基础信息
export function getBaseList() {
  return requestCenter({
    url: "/equipmentManagement/car-capture",
    method: "get",
    // params: params,
  });
}

//基础信息
export function getHistogram() {
  return requestCenter({
    url: "/shm/dsahboard/api/v1/intention-project/histogram",
    method: "get",
    // params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}
